home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / ida / charset / conv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-28  |  3.0 KB  |  150 lines

  1. /* conv.c
  2.  *
  3.  * Reads a character set from stdin converts and outputs to stdout.
  4.  */
  5.  
  6. #ifndef lint
  7. static char Rcsid[] = "@(#)$Header: /usr/local/src/mail/sendmail/ida/charset/RCS/conv.c,v 1.4 1991/06/28 18:41:20 paul Exp $";
  8.  
  9. #endif
  10.  
  11. /*
  12.  * $Header: /usr/local/src/mail/sendmail/ida/charset/RCS/conv.c,v 1.4 1991/06/28 18:41:20 paul Exp $
  13.  *
  14.  * $Log: conv.c,v $
  15.  * Revision 1.4  1991/06/28  18:41:20  paul
  16.  * Replace older xalloc.c with new version from ../../src/util.c .
  17.  *
  18.  * Revision 1.3  1991/04/05  17:06:30  paul
  19.  * Eliminated constant strings passed as arguments.
  20.  *
  21.  * Revision 1.2  1991/04/05  15:56:39  paul
  22.  * Adapted to use the new strcnv.c
  23.  *
  24.  */
  25.  
  26.  
  27. #include "sendmail.h"
  28. #include <errno.h>
  29.  
  30. #define SLEN    256        /* max length in octets of images */
  31. static CHARSET *in;
  32. static CHARSET *out;
  33.  
  34.  
  35. main (argc, argv)
  36.     int     argc;
  37.     char   **argv;
  38. {
  39.     CHAR8U     s[SLEN], r[SLEN];
  40.     char dk[3], us[3];
  41.  
  42.     (void) strcpy(dk, "DK");
  43.     (void) strcpy(us, "us");
  44.  
  45.     switch (argc) {
  46.         case 1:
  47.         in = getchset (dk, '&');
  48.         out = getchset (us, DEFAULT_ESCAPE);
  49.         break;
  50.  
  51.         case 3:
  52.         in = getchset (argv[1], DEFAULT_ESCAPE);
  53.         out = getchset (argv[2], DEFAULT_ESCAPE);
  54.         break;
  55.  
  56.         case 5:
  57.         in = getchset (argv[1], (INT16S) atoi (argv[2]));
  58.         out = getchset (argv[3], (INT16S) atoi (argv[4]));
  59.         break;
  60.  
  61.         default:
  62.         printf ("\n\nUsage:  %s charset-in   [escape-in]  charset-out  [escape-out]\n\n", argv[0]);
  63.         exit (1);
  64.     }
  65.  
  66.     if (in == NULL || out == NULL) {
  67.         printf ("\n\n*** Error: Unknown Charset/s\n\n");
  68.         exit (1);
  69.     }
  70.     /*
  71.      * Should output records of unlimited length by outputting one part at
  72.      * a time.
  73.      */
  74.     while (fgets (s, SLEN, stdin)) {
  75.         strncnv (out, in, r, s, SLEN);
  76.         fputs (r, stdout);
  77.     }
  78.     exit (0);
  79. }
  80. /*
  81. **  DFOPEN -- determined file open
  82. **
  83. **    This routine has the semantics of fopen, except that it will
  84. **    keep trying a few times to make this happen.  The idea is that
  85. **    on very loaded systems, we may run out of resources (inodes,
  86. **    whatever), so this tries to get around it.
  87. */
  88.  
  89. FILE *
  90. dfopen(filename, mode)
  91.     const char *filename;
  92.     const char *mode;
  93. {
  94.     register int tries;
  95.     register FILE *fp;
  96.  
  97.     for (tries = 0; tries < 10; tries++)
  98.     {
  99.         sleep((unsigned) (10 * tries));
  100.         errno = 0;
  101.         fp = fopen(filename, mode);
  102.         if (fp != NULL)
  103.             break;
  104.         if (errno != ENFILE && errno != EINTR)
  105.             break;
  106.     }
  107.     errno = 0;
  108.     return (fp);
  109. }
  110. /*
  111. **  XALLOC -- Allocate memory and bitch wildly on failure.
  112. **
  113. **    THIS IS A CLUDGE.  This should be made to give a proper
  114. **    error -- but after all, what can we do?
  115. **
  116. **    Parameters:
  117. **        sz -- size of area to allocate.
  118. **
  119. **    Returns:
  120. **        pointer to data region.
  121. **
  122. **    Side Effects:
  123. **        Memory is allocated.
  124. */
  125.  
  126. #ifdef __STDC__
  127. void *
  128. #else /* !__STDC__ */
  129. char *
  130. #endif /* __STDC__ */
  131. xalloc(sz)
  132.     register int sz;
  133. {
  134. #ifdef __STDC__
  135.     register void *p;
  136. #else /* !__STDC__ */
  137.     register char *p;
  138. #endif /* __STDC__ */
  139.  
  140.     p = malloc((unsigned) sz);
  141.     if (p == NULL)
  142.     {
  143.         syserr("Out of memory!!");
  144.         abort();
  145.         /* exit(EX_UNAVAILABLE); */
  146.     }
  147.     bzero((char *) p, sz);
  148.     return (p);
  149. }
  150.